home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / Freeware / ttengine-5.0 / Examples / PlainTest / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-05  |  12.6 KB  |  292 lines

  1. /* test ttrender */
  2.  
  3. #define __NOLIBBASE__
  4.  
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/intuition.h>
  8. #include <proto/graphics.h>
  9. #include <proto/ttengine.h>
  10. #include <proto/asl.h>
  11.  
  12. #include <libraries/ttengine.h>
  13.  
  14. extern struct Library *SysBase, *DOSBase;
  15.  
  16. /*----------------------------------------------------------------------------------------------------*/
  17.  
  18. static STRPTR get_font_name(struct Library *AslBase)
  19.   {
  20.     struct FileRequester *freq;
  21.     STRPTR name = NULL;
  22.  
  23.     if (freq = AllocAslRequestTags(ASL_FileRequest, TAG_END))
  24.       {
  25.         if (AslRequestTags(freq,
  26.           ASLFR_TitleText, (ULONG)"Select TrueType font",
  27.           ASLFR_InitialDrawer, (ULONG)"FONTS:",
  28.           ASLFR_DoPatterns, TRUE,
  29.           ASLFR_InitialPattern, (ULONG)"#?.ttf",
  30.           ASLFR_RejectIcons, TRUE,
  31.           TAG_END))
  32.           {
  33.             ULONG namelen = strlen(freq->fr_File) + strlen(freq->fr_Drawer) + 4;
  34.  
  35.             if (name = AllocVec(namelen + 1, MEMF_ANY | MEMF_CLEAR))
  36.               {
  37.                 strncpy(name, freq->fr_Drawer, namelen);
  38.                 AddPart(name, freq->fr_File, namelen);
  39.               }
  40.           }
  41.         FreeAslRequest(freq);
  42.       }
  43.     return name;
  44.   }
  45.  
  46. /*----------------------------------------------------------------------------------------------------*/
  47.  
  48. static VOID free_font_name(STRPTR name)
  49.   {
  50.     if (name) FreeVec(name);
  51.   }
  52.  
  53. /*----------------------------------------------------------------------------------------------------*/
  54.  
  55. UWORD tx[] = {'T', 'e', 's', 't', ' ', '1', '6', '-', 'b', 'i', 't', ' ', 'U', 'n', 'i',
  56.  'c', 'o', 'd', 'e', ' ', 's', 't', 'r', 'i', 'n', 'g', '.', 0x0000};
  57.  
  58. int Main (void)
  59.   {
  60.     struct Library *TTEngineBase, *IntuitionBase, *GfxBase, *AslBase;
  61.     struct Window *win;
  62.     STRPTR fontname;
  63.     APTR font;
  64.  
  65.     if (GfxBase = OpenLibrary("graphics.library", 39))
  66.       {
  67.         if (IntuitionBase = OpenLibrary("intuition.library", 39))
  68.           {
  69.             if (AslBase = OpenLibrary("asl.library", 38))
  70.               {
  71.                 if (fontname = get_font_name(AslBase))
  72.                   {
  73.                     if (TTEngineBase = OpenLibrary("ttengine.library", 4))
  74.                       {
  75.                         if (win = OpenWindowTags(NULL,
  76.                           WA_Top, 25,
  77.                           WA_Left, 0,
  78.                           WA_Width, 640,
  79.                           WA_Height, 350,
  80.                           WA_CloseGadget, TRUE,
  81.                           WA_DragBar, TRUE,
  82.                           WA_DepthGadget, TRUE,
  83.                           WA_IDCMP, IDCMP_CLOSEWINDOW,
  84.                           WA_Title, (ULONG)"ttengine.library test",
  85.                           TAG_END))
  86.                           {
  87.                             ULONG sigmask, signals;
  88.                             BOOL running = TRUE;
  89.                             struct RastPort *rp = win->RPort;
  90.  
  91.                             if (font = TT_OpenFont(
  92.                               TT_FontFile, (ULONG)fontname,
  93.                               TT_FontSize, 24,
  94.                             TAG_END))
  95.                               {
  96.                                 if (TT_SetFont(rp, font))
  97.                                   {
  98.                                     TT_SetAttrs(rp, TT_Window, (ULONG)win, TAG_END);
  99.  
  100.                                     SetAPen(rp, 2);
  101.                                     SetDrMd(rp, JAM1);
  102.                                     Move(rp, 10, 50);
  103.                                     TT_Text(rp, "This is a text printed with TT_Text().", 38);
  104.  
  105.                                     TT_SetAttrs(rp,
  106.                                       TT_Antialias, TT_Antialias_Off,
  107.                                       TT_Encoding, TT_Encoding_Unicode,
  108.                                     TAG_END);
  109.  
  110.                                     SetDrMd(rp, JAM2);
  111.                                     SetBPen(rp, 3);
  112.                                     Move(rp, 10, 74);
  113.                                     TT_Text(rp, tx, 27);
  114.                                   }
  115.                                 else PutStr("TT_SetFont() failed.\n");
  116.                                 TT_CloseFont(font);
  117.                               }
  118.                             else PutStr("Font open failed.\n");
  119.  
  120.                             if (font = TT_OpenFont(
  121.                               TT_FontFile, (ULONG)fontname,
  122.                               TT_FontSize, 36,
  123.                             TAG_END))
  124.                               {
  125.                                 if (TT_SetFont(rp, font))
  126.                                   {
  127.                                     TT_SetAttrs(rp,
  128.                                       TT_Encoding, TT_Encoding_Default,
  129.                                       TT_Antialias, TT_Antialias_On,
  130.                                       TT_Window, (ULONG)win,
  131.                                     TAG_END);
  132.  
  133.                                     SetAPen(rp, 1);
  134.                                     SetBPen(rp, 2);
  135.                                     SetDrMd(rp, JAM2);
  136.                                     Move(rp, 10, 120);
  137.                                     TT_Text(rp, "Antialias with 36 points size.", 30);
  138.                                   }
  139.                                 else PutStr("TT_SetFont() failed.\n");
  140.                                 TT_CloseFont(font);
  141.                               }
  142.                             else PutStr("Font open failed.\n");
  143.  
  144.                             if (font = TT_OpenFont(
  145.                               TT_FontFile, (ULONG)fontname,
  146.                               TT_FontSize, 16,
  147.                             TAG_END))
  148.                               {
  149.                                 if (TT_SetFont(rp, font))
  150.                                   {
  151.                                     TT_SetAttrs(rp,
  152.                                       TT_Encoding, TT_Encoding_Default,
  153.                                       TT_Antialias, TT_Antialias_On,
  154.                                       TT_Window, (ULONG)win,
  155.                                     TAG_END);
  156.  
  157.                                     SetAPen(rp, 1);
  158.                                     SetDrMd(rp, JAM1);
  159.                                     Move(rp, 10, 140);
  160.                                     TT_Text(rp, "Antialias with 16 points size.", 30);
  161.                                     SetAPen(rp, 2);
  162.                                     Move(rp, 10, 156);
  163.                                     TT_Text(rp, "Antialias with 16 points size.", 30);
  164.                                     SetAPen(rp, 3);
  165.                                     Move(rp, 10, 172);
  166.                                     TT_Text(rp, "Antialias with 16 points size.", 30);
  167.                                   }
  168.                                 else PutStr("TT_SetFont() failed.\n");
  169.                                 TT_CloseFont(font);
  170.                               }
  171.                             else PutStr("Font open failed.\n");
  172.  
  173.                             /* antialias on different backgrounds */
  174.  
  175.                             if (font = TT_OpenFont(
  176.                               TT_FontFile, (ULONG)fontname,
  177.                               TT_FontSize, 24,
  178.                             TAG_END))
  179.                               {
  180.                                 ULONG red, grn, blu;
  181.  
  182.                                 red = ObtainBestPen(win->WScreen->ViewPort.ColorMap, 0xFFFFFFFF, 0, 0, TAG_END);
  183.                                 grn = ObtainBestPen(win->WScreen->ViewPort.ColorMap, 0, 0xFFFFFFFF, 0, TAG_END);
  184.                                 blu = ObtainBestPen(win->WScreen->ViewPort.ColorMap, 0, 0, 0xFFFFFFFF, TAG_END);
  185.  
  186.                                     if (TT_SetFont(rp, font))
  187.                                       {
  188.                                     TT_SetAttrs(rp,
  189.                                       TT_Encoding, TT_Encoding_Default,
  190.                                       TT_Antialias, TT_Antialias_On,
  191.                                       TT_Window, (ULONG)win,
  192.                                     TAG_END);
  193.  
  194.                                     SetDrMd(rp, JAM2);
  195.  
  196.                                     SetBPen(rp, grn);
  197.                                     Move(rp, 10, 200);
  198.                                     SetAPen(rp, red);
  199.                                     TT_Text(rp, "Smooth47", 8);
  200.                                     SetAPen(rp, blu);
  201.                                     TT_Text(rp, "Smooth47", 8);
  202.                                     SetAPen(rp, 1);
  203.                                     TT_Text(rp, "Smooth47", 8);
  204.                                     SetAPen(rp, 2);
  205.                                     TT_Text(rp, "Smooth47", 8);
  206.  
  207.                                     SetBPen(rp, red);
  208.                                     Move(rp, 10, 224);
  209.                                     SetAPen(rp, grn);
  210.                                     TT_Text(rp, "Smooth47", 8);
  211.                                     SetAPen(rp, blu);
  212.                                     TT_Text(rp, "Smooth47", 8);
  213.                                     SetAPen(rp, 1);
  214.                                     TT_Text(rp, "Smooth47", 8);
  215.                                     SetAPen(rp, 2);
  216.                                     TT_Text(rp, "Smooth47", 8);
  217.  
  218.                                     SetBPen(rp, blu);
  219.                                     Move(rp, 10, 248);
  220.                                     SetAPen(rp, red);
  221.                                     TT_Text(rp, "Smooth47", 8);
  222.                                     SetAPen(rp, grn);
  223.                                     TT_Text(rp, "Smooth47", 8);
  224.                                     SetAPen(rp, 1);
  225.                                     TT_Text(rp, "Smooth47", 8);
  226.                                     SetAPen(rp, 2);
  227.                                     TT_Text(rp, "Smooth47", 8);
  228.  
  229.                                     SetBPen(rp, 1);
  230.                                     Move(rp, 10, 272);
  231.                                     SetAPen(rp, red);
  232.                                     TT_Text(rp, "Smooth47", 8);
  233.                                     SetAPen(rp, grn);
  234.                                     TT_Text(rp, "Smooth47", 8);
  235.                                     SetAPen(rp, blu);
  236.                                     TT_Text(rp, "Smooth47", 8);
  237.                                     SetAPen(rp, 2);
  238.                                     TT_Text(rp, "Smooth47", 8);
  239.  
  240.                                     SetBPen(rp, 2);
  241.                                     Move(rp, 10, 296);
  242.                                     SetAPen(rp, red);
  243.                                     TT_Text(rp, "Smooth47", 8);
  244.                                     SetAPen(rp, grn);
  245.                                     TT_Text(rp, "Smooth47", 8);
  246.                                     SetAPen(rp, 1);
  247.                                     TT_Text(rp, "Smooth47", 8);
  248.                                     SetAPen(rp, blu);
  249.                                     TT_Text(rp, "Smooth47", 8);
  250.                                   }
  251.                                 else PutStr("TT_SetFont() failed.\n");
  252.  
  253.                                 ReleasePen(win->WScreen->ViewPort.ColorMap, red);
  254.                                 ReleasePen(win->WScreen->ViewPort.ColorMap, grn);
  255.                                 ReleasePen(win->WScreen->ViewPort.ColorMap, blu);
  256.  
  257.                                 TT_CloseFont(font);
  258.                               }
  259.                             else PutStr("Font open failed.\n");
  260.  
  261.                             sigmask = SIGBREAKF_CTRL_C | (1 << win->UserPort->mp_SigBit);
  262.                             while (running)
  263.                               {
  264.                                 signals = Wait(sigmask);
  265.                                 if (signals & SIGBREAKF_CTRL_C) running = FALSE;
  266.                                 if (signals & (1 << win->UserPort->mp_SigBit))
  267.                                   {
  268.                                     struct IntuiMessage *imsg;
  269.  
  270.                                     while (imsg = (struct IntuiMessage*)GetMsg(win->UserPort))
  271.                                       {
  272.                                         if (imsg->Class == IDCMP_CLOSEWINDOW) running = FALSE;
  273.                                         ReplyMsg((struct Message*)imsg);
  274.                                       }
  275.                                   }
  276.                               }
  277.                              TT_DoneRastPort(rp);
  278.                             CloseWindow(win);
  279.                           }
  280.                         CloseLibrary(TTEngineBase);
  281.                       }
  282.                     free_font_name(fontname);
  283.                   }
  284.                 CloseLibrary(AslBase);
  285.               }
  286.             CloseLibrary(IntuitionBase);
  287.           }
  288.         CloseLibrary(GfxBase);
  289.       }
  290.     return 0;
  291.   }
  292.